import Vue from 'vue'
import Router from 'vue-router'
import approvalsRouter from './moudles/approvals'
import departmentsRouter from './moudles/departments'
import employeesRouter from './moudles/employees'
import permissionRouter from './moudles/permission'
import attendancesRouter from './moudles/attendances'
import salarysRouter from './moudles/salarys'
import settingRouter from './moudles/setting'
import socialRouter from './moudles/social'



Vue.use(Router)

/* Layout */
import Layout from '@/layout'

//静态路由（不用权限就可以访问）
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },


  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  //员工导入的路由
  {path: '/import',
    component:Layout,
    hidden: true,  //不显示在左侧菜单中
    children: [{
    path: '', //什么都不写表示二级路由
      component:() => import('@/views/import/index')
    }]

  },



  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

//动态路由（需要权限才可以访问）
export const asyncRoutes = [
  approvalsRouter,
  departmentsRouter,
  employeesRouter,
  permissionRouter,
  attendancesRouter,
  salarysRouter,
  settingRouter,
  socialRouter
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes,...asyncRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
